package org.dromara.system.dict.support;

import org.apache.commons.lang3.StringUtils;
import org.dromara.system.dict.cache.DictionaryCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Map;
import java.util.Objects;

@Service
public class DictSupport {

    @Autowired
    private DictionaryCache dictionaryCache;

    public DictSupport() {
    }

    public Map<String, String> nameMap(String type) {
        if (StringUtils.isBlank(type)) {
            return Collections.emptyMap();
        } else {
            Map<String, String> map = this.dictionaryCache.get(type);
            return !Objects.isNull(map) && !map.isEmpty() ? map : this.dictionaryCache.load().getOrDefault(type, Collections.emptyMap());
        }
    }
}
